package src.com.qf.dao.impl;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import src.com.qf.dao.GoodTypeDao;
import src.com.qf.entity.GoodType;
import src.com.qf.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

public class GoodTypeDaoImpl implements GoodTypeDao {
    QueryRunner queryRunner = new QueryRunner();
    @Override
    public List<GoodType> selectGoodType() {
        String sql = "select *from tb_good_type where parentId = 0";
        List<GoodType> query = null;
        try {
            query = queryRunner.query(JdbcUtil.getCon(), sql, new BeanListHandler<>(GoodType.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }

    @Override
    public GoodType selectGoodTypeById(Integer typeId) {
        String sql = "select *from tb_good_type where id = ?";
        GoodType query = null;
        try {
            query = queryRunner.query(JdbcUtil.getCon(), sql, new BeanHandler<>(GoodType.class),typeId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }

}
